// RegisterInfo.h: interface for the RegisterInfo class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_REGISTERINFO_H__201FA797_0250_4F3F_AA5B_C453C9F9A8A8__INCLUDED_)
#define AFX_REGISTERINFO_H__201FA797_0250_4F3F_AA5B_C453C9F9A8A8__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

template<class Key, class Style> class RegisterInfo  
{
public:
	RegisterInfo(const Key& key, const CString& strStyleName, Style (*pCreateObject)()){ 
		m_strStyleName = strStyleName;
		m_pCreateObject = pCreateObject;
		m_key = key;}

	virtual ~RegisterInfo(){}

public:
	virtual Style CreateObject(){
		return (*m_pCreateObject)();
	}

	Key GetKey() const {
		return m_key;
	}

	CString GetStyleName() const {
		return m_strStyleName;
	}

private:
	Style (*m_pCreateObject)();
	CString m_strStyleName;
	Key m_key;

};

template <class Key, class Style> class SingleInstanceRegisterInfo : public RegisterInfo<Key, Style>
{
public:
	SingleInstanceRegisterInfo(const Key& key, const CString& strStyleName, Style (*pCreateObject)()):
	  RegisterInfo<Key, Style>(key, strStyleName, pCreateObject)
	  {m_pInstance = NULL;}

	  ~SingleInstanceRegisterInfo(){
		  if(m_pInstance != NULL)
			  delete m_pInstance;
	  }


public:
	Style CreateObject(){
		if(m_pInstance != NULL)
			return m_pInstance;
		m_pInstance = RegisterInfo<Key, Style>::CreateObject();
		return m_pInstance;
	}

private:
	Style m_pInstance;
};
#endif // !defined(AFX_REGISTERINFO_H__201FA797_0250_4F3F_AA5B_C453C9F9A8A8__INCLUDED_)
